package com.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.mapper.Oms_Order_Return_Reason_Mapper;
import com.shop.pojo.oms.Oms_Order_Return_Reason;
import com.shop.service.Oms_Order_Return_Reason_Service;
import com.shop.utils.LayuiUtils;
import com.shop.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 退货原因-李贝贝
 */
@Service
public class Oms_Order_Return_Reason_ServiceImpl implements Oms_Order_Return_Reason_Service {

    @Autowired
    private Oms_Order_Return_Reason_Mapper oms_order_return_reason_mapper;

    /**
     * 显示所有退货原因
     * @param pages
     * @param oms_order_return_reason
     * @return
     */
    @Override
    public LayuiUtils<Oms_Order_Return_Reason> find_oms_order_return_reason(Page<Oms_Order_Return_Reason> pages, Oms_Order_Return_Reason oms_order_return_reason) {
        LayuiUtils<Oms_Order_Return_Reason> layuiUtils = new LayuiUtils<>();
        QueryWrapper<Oms_Order_Return_Reason> queryWrapper = new QueryWrapper<>();
        if (oms_order_return_reason.getName() != null){
            queryWrapper.like("name",oms_order_return_reason.getName());
        }
        Page<Oms_Order_Return_Reason> oms_order_return_reasonPage = oms_order_return_reason_mapper.selectPage(pages,queryWrapper);
        layuiUtils.setCount(oms_order_return_reasonPage.getTotal());
        layuiUtils.setData(oms_order_return_reasonPage.getRecords());
        return layuiUtils;
    }

    /**
     * 新增
     * @param oms_order_return_reason
     * @return
     */
    @Override
    public R insert_oms_order_return_reason(Oms_Order_Return_Reason oms_order_return_reason) {
        int insert = oms_order_return_reason_mapper.insert(oms_order_return_reason);
        if (insert > 0){
            return R.success();
        }
        return R.error(500,"添加失败");
    }

    /**
     * 删除退货原因
     * @param id
     * @return
     */
    @Override
    public R delete_oms_order_return_reason(List<Long> id) {
        int delete = oms_order_return_reason_mapper.deleteBatchIds(id);
        if (delete > 0){
            return R.success();
        }
        return R.error(500,"删除失败");
    }

    /**
     * 修改
     * @param oms_order_return_reason
     * @return
     */
    @Override
    public R update_oms_order_return_reason(Oms_Order_Return_Reason oms_order_return_reason) {
        int update = oms_order_return_reason_mapper.updateById(oms_order_return_reason);
        if (update > 0){
            return R.success();
        }
        return R.error(500,"修改失败");
    }
}
